package com.burgeon.backend.SHOP.rest.recharger;
/**
 * 查询余额充值记录 ID
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOP.entity.recharge.ResultRecharge;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindRECHARGEById extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindRECHARGEById(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     * @return
     */

    public ResultRecharge getData(String id) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(id),url);
        System.err.println(str);

        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)){
            throw new Exception(message);
        }
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");


            JSONArray array = jsonArray.getJSONArray(0);
        ResultRecharge resultRecharge = new ResultRecharge();
            resultRecharge.setId(array.getString(0));
            resultRecharge.setPrice(array.getString(1));
            resultRecharge.setAmount(array.getString(2));
            resultRecharge.setState(array.getString(3).equals("提交")?"Y":"N");
            resultRecharge.setBalance(array.getString(4));
            resultRecharge.setCode(array.getString(5));
            resultRecharge.setOpenid(array.getString(6));
            resultRecharge.setPhone(array.getString(7));
            resultRecharge.setDate(array.getString(8));
             resultRecharge.setGive(array.getString(9));


        return resultRecharge;
    }

    private MultiValueMap Data(String id) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("ID");


        columns.add("'TOT_AMT_DEPOSIT'");//充值金额
        columns.add("'TOT_AMT_ACTUAL'");//充值总额
        columns.add("'STATUS'");//提交状态
        //columns.add("TOT_AMT_ACTUALSY");//剩余金额
        columns.add("'C_VIP_ID;FA_VIPACC_ID;AMOUNT'");//储值余额
        columns.add("DOCNO");
        columns.add("'C_VIP_ID;OPENID'");
        columns.add("'C_VIP_ID;MOBIL'");
        columns.add("BILLDATE");//单据日期
        columns.add("TOT_AMT_GIVE");//赠送

        params.put("columns", columns);
        params.put("table", "YC_VIPMONEY");//表名

        params.put("count","true");



        HashMap paramss = new HashMap();
        String ac = "'"+ id+"'";
        paramss.put("column", "'ID'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params,account,password);
    }
    public static void main(String[] args) {
        FindRECHARGEById getRetailByVip = new FindRECHARGEById("47.92.53.75:90", "dy@xcx.com", "123");
        try {
            System.err.println(getRetailByVip.getData("6"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
